<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <title>Document</title>
</head>

<body>
    <script>
        /*函数作用域
            1）全局作用域
            2）局部作用域
            3）闭包：让一个外部函数访问到另一个函数局部的变量的函数（函数的嵌套）*/
        let a = 123;

        function fn() {
            function fc() {
                let b = 234;
            }
        }
        console.log(a); //123
        console.log(b); //undefined

        //闭包
        function fn() {
            let b = 123;

            function temp() {
                return b;
            }
            return temp;
        }
        let f = fn();

        let b1 = f();
        let b2 = f();
        console.log(b1, b2, b1 == b2);//123，123，true
    </script>
</body>

</html>